package br.com.center.loja.ws.dto.converter;

import java.util.ArrayList;
import java.util.List;

import br.com.center.loja.model.Client;
import br.com.center.loja.ws.dto.ClientDTO;

public class ClientDTOConverter implements Converter<Client, ClientDTO> {

	private AddressDTOConverter addressConverter = new AddressDTOConverter();
	
	@Override
	public ClientDTO to(Client element) {
		ClientDTO dto = new ClientDTO();
		dto.setAddress(addressConverter.to(element.getAddress()));
		dto.setBirthday(element.getBirthday());
		dto.setCode(element.getCode());
		dto.setDocument(element.getDocument());
		dto.setEmail(element.getEmail());
		dto.setName(element.getName());
		dto.setPhone(element.getPhone());
		dto.setUser(element.getUser());
		
		return dto;
	}

	@Override
	public Client from(ClientDTO element) {
		Client client = new Client();
		client.setAddress(addressConverter.from(element.getAddress()));
		client.setBirthday(element.getBirthday());
		client.setCode(element.getCode());
		client.setDocument(element.getDocument());
		client.setEmail(element.getEmail());
		client.setName(element.getName());
		client.setPhone(element.getPhone());
		client.setUser(element.getUser());
		
		return client;
	}

	@Override
	public List<ClientDTO> to(List<Client> elements) {
		List<ClientDTO> result = new ArrayList<ClientDTO>();
		
		for (Client element : elements) {
			result.add(to(element));
		}
		
		return result;
	}

	@Override
	public List<Client> from(List<ClientDTO> elements) {
		List<Client> result = new ArrayList<Client>();
		
		for (ClientDTO element : elements) {
			result.add(from(element));
		}
		
		return result;
	}

}
